package com.itheima.controller;

import com.itheima.R;
import com.itheima.pojo.SmsHomeBrand;
import com.itheima.pojo.SmsHomeRecommendProduct;
import com.itheima.service.SmsHomeBrandService;
import com.itheima.service.SmsHomeRecommendProductService;
import com.itheima.vo.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author Hakuna Matata
 * @date 2022-10-13-18:30
 */

@RestController
@RequestMapping("home/recommendProduct")
public class SmsHomeRecommendProductController {

    @Autowired
    private SmsHomeRecommendProductService recommendProductService;

    /**
     * 添加首页推荐
     */
    @PostMapping("/create")
    public R recommendProductCreate(@RequestBody SmsHomeRecommendProduct recommendProduct) {
        recommendProductService.recommendProductCreate(recommendProduct);
        return R.success("添加首页推荐成功!");
    }

    /**
     * 批量删除
     */
    @PostMapping("/delete")
    public R recommendProductDelete(Integer[] ids) {
        recommendProductService.recommendProductDelete(ids);
        return R.success("批量删除人气推荐");
    }

    /**
     * 分页查询推荐品牌
     */
    @GetMapping("/list")
    public R recommendProductList(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                  @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                  String productName,
                                  Integer recommendStatus) {
        PageResult result = recommendProductService.recommendProductList(pageNum, pageSize, productName, recommendStatus);
        return R.success(result);
    }

    /**
     * 批量修改状态
     *
     * @param ids
     * @param recommendStatus
     * @return
     */
    @PostMapping("/update/recommendStatus")
    public R updateRecommendStatus(Integer[] ids, Integer recommendStatus) {
        recommendProductService.updateRecommendStatus(ids, recommendStatus);
        return R.success("批量修改状态功能执行");
    }

    /**
     * 修改排序
     *
     * @param id
     * @param sort
     * @return
     */
    @PostMapping("/update/sort/{id}")
    public R updateSortByid(@PathVariable Long id, Integer sort) {
        recommendProductService.updateSortById(id, sort);
        return R.success("修改人气推荐排序功能执行");
    }
}
